//
//  ViewController.m
//  XML实现数据存储
//
//  Created by 伍银荣 on 2021/6/26.
//  Copyright © 2021 com.example. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
//存数据
- (IBAction)saveBtnClicked:(id)sender {
    //获取沙盒根目录文
    NSString *home = NSHomeDirectory();
    //拼接Documents的目录
    //第一种方法
   // NSString *docPath = [home stringByAppendingString:@"/Documents"];
    //第二种方法:不建议使用这种方式,因为新版本的操作系统可能会修改目录
   // NSString * docPath = [home stringByAppendingPathComponent:@"Documents"];
    //第三种方法:NSDocumentDirectory:存放在那个文件夹下.
    //NSUserDomainMask:用户的主目录(代表从用户文件夹下找)
    //YES:代表展开路径中的波浪字符"~"
    NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES)[0];
    
    //拼接文件
    NSString *filePath = [docPath stringByAppendingPathComponent:@"xxx.plist"];
    //NSArray *arr = @[@"1",@"2",@"3",@"4"];
    NSDictionary *dict = @{
                           @"key": @"value",
                           @"name": @"Jack",
                           @"age": @12,
                           };
    //将数组写入文件中
    [dict writeToFile:filePath atomically:YES];
}

//取数据
- (IBAction)readBtnClicked:(id)sender {
    NSString *docPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *filePath = [docPath stringByAppendingPathComponent:@"xxx.plist"];
    //NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
    NSLog(@"dict = %@",dict);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    ///Users/wuyinrong/Library/Developer/CoreSimulator/Devices/4A01C773-8C71-40FA-B165-F3F5207BA129/data/Containers/Data/Application/117CA094-59AB-4462-A5A0-E24AF6B71E06
    NSString *str = NSHomeDirectory();
    NSLog(@"沙盒路径:%@",str);
    
    
}


@end
